package com.gome.ocean.service.datax.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.gome.ocean.dao.datax.IExportDAO;
import com.gome.ocean.dao.model.datasource.ExportBean;
import com.gome.ocean.service.datax.IExportService;

/**
 * @author zhangguoqing 2016年12月28日 下午3:44:24
 * @since 5.0.0
 */
@Service("iExportService")
@Transactional("transactionManager")
public class ExportServiceImpl implements IExportService {

    private static final Logger LOG = LoggerFactory.getLogger(ExportServiceImpl.class);

    @Autowired
    private IExportDAO iExportDAO;

    @Override
    public boolean insert(ExportBean bean) {
        boolean flag = false;
        try {
            iExportDAO.insert(bean);
            flag = true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return flag;
    }

    @Override
    public boolean update(ExportBean bean) {
        boolean flag = false;
        try {
            iExportDAO.update(bean);
            flag = true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return flag;
    }

    @Override
    public boolean delete(Long id) {
        boolean flag = false;
        try {
            iExportDAO.delete(id);
            flag = true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return flag;
    }

    @Override
    public ExportBean getBeanByMap(Map<String, Object> map) {
        ExportBean export = null;
        try {
            export = iExportDAO.getBeanByMap(map);
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return export;
    }

    @Override
    public Page<ExportBean> getBeanListsByMap(Map<String, Object> map, Integer pageNum, Integer pageSize) {
        try {
            List<ExportBean> exportLists = iExportDAO.getBeanListsByMap(map, new RowBounds(pageNum, pageSize));
            if (exportLists != null && exportLists.size() > 0) {
                return (Page<ExportBean>) exportLists;
            }
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return null;
    }

    @Override
    public Page<ExportBean> getBeanListsByProject(List<String> projects, Integer pageNum, Integer pageSize) {
        try {
            List<ExportBean> exportLists = iExportDAO.getBeanListsByProject(projects, new RowBounds(pageNum, pageSize));
            if (exportLists != null && exportLists.size() > 0) {
                return (Page<ExportBean>) exportLists;
            }
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return null;
    }

    @Override
    public Long getMaxId() {
        Long maxId = iExportDAO.getMaxId();
        if (maxId == null) {
            maxId = 0L;
        }
        return maxId + 1L;
    }

}
